import {ApiProperty} from '@nestjs/swagger';
import {DocumentType, ModelOptions, prop} from '@typegoose/typegoose';
import * as bcrypt from 'bcryptjs'

export type UserDocument = DocumentType<User>

@ModelOptions({
  schemaOptions: {
    timestamps: true,
    versionKey: false,
  },
})
export class User {
  @ApiProperty({description: '用户名', example: 'user1', required: true})
  @prop({unique: true})
  username: string;

  @ApiProperty({description: '密码', example: 'pass1', required: true})
  @prop({
    select: false,
    set(value: string) {
      return bcrypt.hashSync(value)
    }
  })
  password: string;

  @ApiProperty({description: '头像'})
  @prop()
  avatar?: string;

  @ApiProperty({description: '个人简介'})
  @prop()
  description?: string
}
